package com.ctgu.蓝桥杯真题.B组2019;


import java.io.*;
import java.util.*;

/**
 * @author: Backdiy
 * @data: 2021/4/11 13:35
 * @desc:
 */
public class G外卖店的优先级 {
    public static void main(String[] args) throws IOException {
        int n = Input.nextInt();
        int m = Input.nextInt();
        int t = Input.nextInt();
        int ans = 0;
        ArrayList<Pair> pairs = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            int x = Input.nextInt();
            int y = Input.nextInt();
            pairs.add(new Pair(x, y));
        }
        pairs.sort((o1, o2) -> {
            if (o1.getKey().equals(o2.getKey())) {
                return o1.getValue() - o2.getValue();
            }
            return o1.getKey() - o2.getKey();
        });
        Map<Integer, Store> storeMap = new HashMap<>();
        for (Pair pair :
                pairs) {
            int x = pair.getValue();
            int y = pair.getKey();
            if (storeMap.containsKey(x)) {
                Store store = storeMap.get(x);
                int time = store.time;
                int score = store.score;
                boolean flag = store.flag;
                if (time == y) {
                    score += 2;
                } else {
                    score = Math.max(score - y + time + 1, 0);
                    if (score <= 3) {
                        flag = false;
                    }
                    score = score + 2;
                }
                if (score > 5) {
                    flag = true;
                } else {
                    if (score <= 3) {
                        flag = false;
                    }
                }
                storeMap.put(x, new Store(y, score, flag));
            } else {
                storeMap.put(x, new Store(y, 2, false));
            }
        }
        for (Store store :
                storeMap.values()) {
            int time = store.time;
            int score = store.score;
            boolean flag = store.flag;
            score = Math.max(0, score - t + time);
            if (score > 5) {
                flag = true;
            } else {
                if (score <= 3) {
                    flag = false;
                }
            }
            if (flag) {
                ans++;
            }
        }
        Input.out.println(ans);
        Input.out.flush();
    }

    static class Input {
        static StreamTokenizer streamTokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static PrintWriter out = new PrintWriter((new OutputStreamWriter(System.out)));
        static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        static int nextInt() throws IOException {
            streamTokenizer.nextToken();
            return (int) streamTokenizer.nval;
        }

        static double nextDouble() throws IOException {
            streamTokenizer.nextToken();
            return streamTokenizer.nval;
        }

        static long nextLong() throws IOException {
            streamTokenizer.nextToken();
            return (long) streamTokenizer.nval;
        }

        static String nextLine() throws IOException {
            return bufferedReader.readLine();
        }

        static char next() throws IOException {
            return (char) bufferedReader.read();
        }
    }
}

class Store {
    public int time;
    public int score;
    public boolean flag;

    public Store(int time, int score, boolean flag) {
        this.time = time;
        this.score = score;
        this.flag = flag;
    }
}

class Pair {
    Integer key;
    Integer value;

    public Integer getKey() {
        return key;
    }


    public Integer getValue() {
        return value;
    }


    public Pair(int key, int value) {
        this.key = key;
        this.value = value;
    }


}